package com.example.springboot_vue.service.impl;

import com.example.springboot_vue.entity.Student;
import com.example.springboot_vue.mapper.StudentMapper;
import com.example.springboot_vue.service.StudentService;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
@Transactional
public class StudentServiceImpl implements StudentService {

    @Resource
    private StudentMapper studentMapper;

    @Override
    public Student findById(Integer id) {
        return studentMapper.findById(id);
    }

    @Override
    public List<Student> findAll() {
        return studentMapper.findAll();
    }

    @Override
    public Map<String, Object> update(Student student) {
        Map<String,Object>map = new HashMap<>();
        studentMapper.update(student);
        map.put("code",200);
        map.put("msg","更新成功");
        return map;

    }

    @Override
    public Map<String, Object> add(Student student) {
        Map<String,Object>map = new HashMap<>();
        studentMapper.add(student);
        map.put("code",200);
        map.put("msg","添加成功");
        return map;

    }

    @Override
    public Map<String, Object> deleteById(Integer id) {
        Map<String,Object>map = new HashMap<>();
        studentMapper.deleteById(id);
        map.put("code",200);
        map.put("msg","删除成功");
        return map;

    }
}
